home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / new_file / programm / gemfsc19 / gemfsc19.lzh / GEMFUNCS / RCUNION.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-08  |  1.4 KB  |  53 lines

  1. /**************************************************************************
  2.  * RCUNION.C - Compute union of 2 GRECT rectangles.
  3.  *             Does not return anything, since by definition the two
  4.  *             rectangles will have common area.
  5.  *************************************************************************/
  6.  
  7. #if defined(__HSC__) || defined (__GNUC__)
  8.  
  9. #include "gemfintl.h"
  10.  
  11. void rc_union(prect1, prect2)
  12.     register GRECT *prect1;
  13.     register GRECT *prect2;
  14. {
  15.     register short    w1, w2;
  16.     short             lx, rx;
  17.     short             ty, by;
  18.  
  19.     /* calc right-side x as the greater x of the two rectangles */
  20.  
  21.     w1 = prect1->g_x + prect1->g_w;
  22.     w2 = prect2->g_x + prect2->g_w;
  23.     rx  = (w1 > w2) ? w1 : w2;
  24.  
  25.     /*  calc bottom y as the greater y of the two rectanlges */
  26.  
  27.     w1 = prect1->g_y + prect1->g_h;
  28.     w2 = prect2->g_y + prect2->g_h;
  29.     by  = (w1 > w2) ? w1 : w2;
  30.  
  31.     /* calc left-side x as the lesser x of the two rectangles */
  32.  
  33.     w1 = prect1->g_x;
  34.     w2 = prect2->g_x;
  35.     lx = (w1 < w2) ? w1 : w2;
  36.  
  37.     /* calc top y as the lesser y of the two rectangles */
  38.  
  39.     w1 = prect1->g_y;
  40.     w2 = prect2->g_y;
  41.     ty = (w1 < w2) ? w1 : w2;
  42.  
  43.     /* store the calculated rectangle (converting back to GRECT-type w/h) */
  44.  
  45.     prect2->g_x = lx;
  46.     prect2->g_y = ty;
  47.     prect2->g_w = rx - lx;
  48.     prect2->g_h = by - ty;
  49.  
  50. }
  51.  
  52. #endif
  53.